#include "stdafx.h"
#include "ccube.h"

CCube::CCube()
{	
	m_r = m_g = m_b = 0;
	m_x =  m_y = m_z  = 0;
	m_rx = m_ry = m_rz = 0;
	m_sx = m_sy = m_sz = 0;
}
CCube::~CCube()
{
}
void CCube::setPosition(double x, double y, double z)
{
	m_x = x;
	m_y = y;
	m_z = z;
}
void CCube::setRotation(double pitch, double yaw, double roll)
{
	m_rx = pitch;
	m_ry = yaw;
	m_rz = roll;
}

void CCube::setScale(double x, double y, double z)
{
	m_sx = x;
	m_sy = y;
	m_sz = z;
}

void CCube::setColor(int r, int g, int b)
{
	m_r = r;
	m_g = g;
	m_b = b;
	GLfloat mat_specular[] = {m_r ,m_g ,m_b, 1.0};
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_specular);
}

void CCube::draw(bool solid)
{	
	//glMatrixMode(GL_MODELVIEW);
	glRotatef(0.f,1.0,0.0,0.0);
	glColor3f(m_r,m_g,m_b);
	glTranslatef(m_x,m_y,m_z);
	glScalef(m_sx,m_sy,m_sz);
		
	GLfloat n1[3]={0, 0, 1}, n2[3]={1, 0, 0}, n3[3]={0, -1, 0};
	GLfloat v1[3]={1, 0, 0}, v2[3]={-1, 0, 0}, v3[3]={0, 1, 0};	

	glPushMatrix();
	
		if(solid)
		{
			glBegin(GL_QUADS);
				glNormal3fv(n1);
				glVertex3f(0, 0, 1);
				glVertex3f(1, 0, 1);		
				glVertex3f(1, 1, 1);
				glVertex3f(0, 1, 1);		
				
				glNormal3fv(v1);				
				glVertex3f(1, 0, 1);
				glVertex3f(1, 0, 0);
				glVertex3f(1, 1, 0);
				glVertex3f(1, 1, 1);

				glNormal3fv(n2);				
				glVertex3f(0, 0, 0);
				glVertex3f(0, 1, 0);
				glVertex3f(1, 1, 0);
				glVertex3f(1, 0, 0);

				glNormal3fv(v2);				
				glVertex3f(0, 1, 1);
				glVertex3f(0, 1, 0);				
				glVertex3f(0, 0, 0);								
				glVertex3f(0, 0, 1);
		
				glNormal3fv(n3);
				glVertex3f(0, 0, 1);
				glVertex3f(0, 0, 0);
				glVertex3f(1, 0, 0);	
				glVertex3f(1, 0, 1);

				glNormal3fv(v3);
				glVertex3f(0, 1, 0);
				glVertex3f(0, 1, 1);
				glVertex3f(1, 1, 1);
				glVertex3f(1, 1, 0);	
		}
		else
		{
			glBegin(GL_LINE_STRIP);
				glNormal3fv(n1);
				glVertex3f(0, 0, 1);
				glVertex3f(1, 0, 1);		
				glVertex3f(1, 1, 1);
				glVertex3f(0, 1, 1);
				glVertex3f(0, 0, 1);
			glEnd();
				
			glBegin(GL_LINE_STRIP);
				glNormal3fv(v1);				
				glVertex3f(1, 0, 1);
				glVertex3f(1, 0, 0);
				glVertex3f(1, 1, 0);
				glVertex3f(1, 1, 1);
				glVertex3f(1, 0, 1);
			glEnd();

			glBegin(GL_LINE_STRIP);
				glNormal3fv(n2);				
				glVertex3f(0, 0, 0);
				glVertex3f(0, 1, 0);
				glVertex3f(1, 1, 0);
				glVertex3f(1, 0, 0);
				glVertex3f(0, 0, 0);
			glEnd();

			glBegin(GL_LINE_STRIP);
				glNormal3fv(v2);				
				glVertex3f(0, 1, 1);
				glVertex3f(0, 1, 0);				
				glVertex3f(0, 0, 0);								
				glVertex3f(0, 0, 1);
				glVertex3f(0, 1, 1);		
			glEnd();


			glBegin(GL_LINE_STRIP);
				glNormal3fv(n3);
				glVertex3f(0, 0, 1);
				glVertex3f(0, 0, 0);
				glVertex3f(1, 0, 0);	
				glVertex3f(1, 0, 1);
				glVertex3f(0, 0, 1);
			glEnd();


			glBegin(GL_LINE_STRIP);
				glNormal3fv(v3);
				glVertex3f(0, 1, 0);
				glVertex3f(0, 1, 1);
				glVertex3f(1, 1, 1);
				glVertex3f(1, 1, 0);
				glVertex3f(0, 1, 0);
							
		}
		glEnd();

	glPopMatrix();	
}
/*
void CCube::setTexture(char *pFilename)
{
	m_idTexture = SOIL_load_OGL_texture(pFilename,0,0,0);
	param= [GL_DECAL,GL_BLEND,GL_MODULATE,GL_ADD,GL_REPLACE,...];	
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
	glEnable (GL_TEXTURE_2D);

	glBindTexture(GLenum target, GLuint textureName);

}*/